package com.xuecheng.content.controller;

import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.TeachplanDto;
import org.simpleframework.xml.Path;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/teachplan")
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;
    /**
     * 课程计划列表-树形结构
     * 请求路径 GET {courseId}/tree-nodes
     * 路径参数 课程ID
     * 响应数据 ResponseResult<TeachplanVo></>
     */
    @GetMapping("{courseId}/tree-nodes")
    public ResponseResult treeNodes(@PathVariable("courseId") Long courseId){
        return teachplanService.treeNodes(courseId);
    }

    /**
     * 保存或这更新课程计划
     * 请求路径POST
     * 请求参数 Dto
     */
    @PostMapping
    public ResponseResult saveOrUpdate(@RequestBody TeachplanDto dto){
        return teachplanService.saveOrUpdatePlan(dto);
    }

    /**
     * 删除
     * 请求路径 DELETE /{id}
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable("id") Long id){
        return teachplanService.delete(id);
    }
}
